# /usr/bin/env python3.6
# -*- encoding: utf-8 -*-
"""
@File    : config.py
@Time    : 2020/2/2 0002 11:41
@Author  : zhangbing
@Email   : 18829172841@163.com
@Software: PyCharm
"""
import datetime
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


def get_db_uri(dbinfo):
    engine = dbinfo.get("ENGINE") or "sqlite"
    driver = dbinfo.get("DEVIER") or "sqlite"
    user = dbinfo.get("USER") or ""
    password = dbinfo.get("PASSWORD") or ""
    host = dbinfo.get("HOST") or "localhost"
    port = dbinfo.get("PORT") or 3306
    db = dbinfo.get("DB") or "test"
    return "{}+{}://{}:{}@{}:{}/{}".format(engine, driver, user, password, host, port, db)


class Config:  # 处理环境相关,此处是基本的配置
    DEBUG = False
    TESTING = False
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SESSION_TYPE = 'redis'
    SESSION_COOKIE_SECURE = True
    SECRET_USE_SIGNER = True  # 是否进行加密处理,使用上述的key进行相关的加密处理
    SECRET_KEY = "test"
    SESSION_KEY_PREFIX = "user-"
    PERMANENT_SESSION_LIFETIME = datetime.timedelta(days=0.5)
    DEBUG_TB_INTERCEPT_REDIRECTS = False


class DevelopConfig(Config):
    DEBUG = True
    dbinfo = {
        "ENGINE": "mysql",
        "DEVIER": "pymysql",
        "USER": "flask",
        "PASSWORD": "flask",
        "DB": "flasktest",
        "PORT": 3306,
        "HOST": "localhost",
    }
    SQLALCHEMY_DATABASE_URI = get_db_uri(dbinfo)


envs = {
    "develop": DevelopConfig,
}

if __name__ == "__main__":
    pass
